package fr.upmc.cie;

import fr.upmc.cie.data.CategorieItem;
import fr.upmc.cie.data.DataManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class CategorieDisplay extends Activity {
	
	private CategorieDisplay self = this;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.category_modif);
		CategorieItem idCateg = (CategorieItem) this.getIntent().getExtras().getSerializable("categorie");

		final Button btAjoutCateg = (Button) this.findViewById(R.id.BoutonAjoutCategorie);
		final Button btSuppCateg = (Button) this.findViewById(R.id.BoutonSupprimerCategorie);
		final EditText categ_title = (EditText) this.findViewById(R.id.cate);
		final CategorieItem itemcat =DataManager.getCategorieManager(self).getCategorieById(idCateg.getId(), self);
		
		categ_title.setText(itemcat.getName());
		btAjoutCateg.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
			itemcat.setName(categ_title.getText().toString());
			DataManager.getCategorieManager(self).updateCategorie(itemcat, self);
			
			Intent i = new Intent();
			self.setResult(2,i);
			finish();
			}
		});
		
		btSuppCateg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				DataManager.getCategorieManager(self).deleteCategorie(itemcat, self);
				Intent i = new Intent();
				
				i.setClass(v.getContext(), ListCategories.class);
				startActivity(i);
			}
		});
		
			
	}
}



